import requests

url = 'https://www.kugou.com/yy/rank/home/1-52144.html?from=rank'
headers = {
    'cookie':'kg_mid=4358317f059b77a8fc558890f8413ee4; kg_dfid=3Mq49K1wrDUo4F46ul0aO2nP; kg_mid_temp=4358317f059b77a8fc558890f8413ee4; kg_dfid_collect=d41d8cd98f00b204e9800998ecf8427e; ACK_SERVER_10017=%7B%22list%22%3A%5B%5B%22gzverifycode.service.kugou.com%22%5D%5D%7D; ACK_SERVER_10015=%7B%22list%22%3A%5B%5B%22gzlogin-user.kugou.com%22%5D%5D%7D; ACK_SERVER_10016=%7B%22list%22%3A%5B%5B%22gzreg-user.kugou.com%22%5D%5D%7D; Hm_lvt_aedee6983d4cfc62f509129360d6bb3d=1761814592,1761908816,1762176664; Hm_lpvt_aedee6983d4cfc62f509129360d6bb3d=1762176664; HMACCOUNT=C702CB4ABF545122',
    'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0'
}


response = requests.get(url, headers=headers)
# print(response.status_code)
# print(response.text)


from lxml import etree
tree = etree.HTML(response.text)
items = tree.xpath('//div[@class="pc_temp_songlist "]/ul/li')


# print(items)
for item in items:
    # print(item.xpath('.//a/@title')[0], item.xpath('.//a/@href')[0])
    temp_data = item.xpath('.//a/@title')[0].split('-')
    # print(temp_data[0], temp_data[1])
    dit = {
        '歌手':temp_data[0],
        '歌名':temp_data[1],
        '详情链接':item.xpath('.//a/@href')[0],
    }

    # print(dit)

    res = requests.get(dit['详情链接'], headers=headers)
    # print(res.status_code)
    print(res.text)
    # datas = etree.HTML(res.text)
    #
    # for data in datas:
    #     print(data)
    # break